package com.ftg.learn.chpater01.chpater02;

/**
 * for循环
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/4/23 13:18
 */

public class LearnFor02 {

    /**
     * 方法 while
     * 代码块里面的变量   形
     *
     * @param well 井深
     * @param jump 跳多高
     * @param down 下滑多少
     * @return index 次数
     */

    public static void checkArguments(int well, int jump, int down) {

        //        容错处理
        if (well < 0) {
            throw new RuntimeException("参数well不能为负数");
        }
        if (down > jump) {
            throw new RuntimeException("输入的数没有意义");
        }
    }

    public static int jumpNoWithWhile(int well, int jump, int down) {

        checkArguments(well, jump, down);
        int frogPosition = 0;
        int index = 0;
        //不明确次数使用while
        while ((frogPosition += jump) < well) {
            index++;
            frogPosition -= down;
        }
        return index;
    }


    public static int jumpNo(int well, int jump, int down) {

        checkArguments(well, jump, down);
        int index = 0;
        for (int i = 0; (i = i + jump) <= well; i -= down) {
            index++;
        }
        return index;
    }

    public static void main(String[] args) {
        System.out.println(jumpNo(7, 3, 1));
        //for (1) go(for) while do while
        // 蛙跳井问题 三种方式  7  3  1 几次跳出  (main,写成一个方法)
        //条件
        //2 循环条件处理

        /******************/
//        a b c (4以内0,不能重复)
//        数据帮助类 Math.random()*5;
//        (int)(Math.random()*5);
        int a = 0, b = 0, c = 0;
        int index = 0;
        while (index < 3) {
            int temp = (int) (Math.random() * 4) + 1;
            if (temp != a && temp != b && temp != c) {
                index++;
                if (index == 1) {
                    a = temp;
                }
                if (index == 2) {
                    b = temp;
                }
                if (index == 3) {
                    c = temp;
                }
            }
        }
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);


    }
}
